﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    using DAL.Entities;

    public class SanPhamDNDAL : BaseDAL, UTL.IBaseDAL
    {
        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            string sql = @" select * from SANPHAMDOANHNGHIEP a join SANPHAM b on a.MASP=b.MASP join DN c on a.MSDN=c.MSDN ";
            return ExecuteQuery(sql);
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(string id)
        {
            throw new NotImplementedException();
        }

        public bool Insert(object obj)
        {
            var o = (sanphamDN)obj;
            string sql = @"set dateformat mdy; INSERT INTO sanphamdoanhnghiep(msdn,masp,sl) VALUES('{0}','{1}',{2}) ";
            sql = string.Format(sql,o.madn,o.masp,o.sl);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (sanphamDN)obj;
            string sql = @"set dateformat mdy; UPDATE sanphamdoanhnghiep SET sl={0} wHERE msdn='{1}' and masp='{2}' ";
            sql = string.Format(sql, o.sl,o.madn,o.masp);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public DataTable Search(string name)
        {
            throw new NotImplementedException();
        }

        public bool deleteobj(object obj)
        {
            var o = (sanphamDN)obj;
            string sql = @"DELETE FROM sanphamdoanhnghiep WHERE msdn = '{0}' and masp='{1}' ";
            sql = string.Format(sql, o.madn, o.masp);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }


        public DataTable select_sp()
        {
            string sql = @"select masp as id,tensp as ten from sanpham";
            return ExecuteQuery(sql);
        }

        public DataTable select_dn()
        {
            string sql = @"select msdn as id,tendn as ten from dn";
            return ExecuteQuery(sql);
        }

    }
}
